<?php

include '../database/koneksi/Koneksi.php';
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Komentar
 *
 * @author BAGUS
 */
class Komentar {

    //put your code here
    var $id_Komentar;
    var $komentar;
    var $id_Pengguna;
    var $id_Barang;
    var $tgl_Komentar;

    public function getId_Komentar() {
        $id = null;
        $koneksi = new Koneksi();
        $koneksi->koneksiDB();
        $hari = date('d');
        $bulan = date('m');
        $tahun = date('Y');
        $substring = substr($tahun, 2);
        $kodeTanggal = $hari . $bulan . $substring;
        $rs1 = mysql_query("select * from komentar where id_komentar like '%" . $kodeTanggal . "%' order by id_komentar");

        if (!$rs1) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }

        while ($row = mysql_fetch_array($rs1)) {
            $id = $row["id_komentar"];
        }
        if ($id != null) {
            $id2 = intval($id);
            $id2++;
            $id = intval($id2);
        } else {
            $id = "5" . $kodeTanggal . "0001";
        }
        return $id;
    }

    public function setKomentar($komentar) {
        $this->komentar = $komentar;
    }

    public function getKomentar() {
        return $this->komentar;
    }

    public function getId_Pengguna() {
        return $this->id_Pengguna;
    }

    public function setId_Pengguna($id_Pengguna) {
        $this->id_Pengguna = $id_Pengguna;
    }

    public function getId_Barang() {
        return $this->id_Barang;
    }

    public function setId_Barang($id_Barang) {
        $this->id_Barang = $id_Barang;
    }
    
    public function getTgl_Komentar() {
        $this->tgl_Komentar = date("Y-m-d H:i:s");
        return $this->tgl_Komentar;
    }

    public function insertKomentar() {
        $kon = new Koneksi();
        $kon->koneksiDB();
        $query = "insert into komentar values('" . mysql_real_escape_string($this->getId_Komentar()) . "','" 
                . mysql_real_escape_string($this->getKomentar()) . "','"  
                . $this->getTgl_Komentar() . "','" 
                . mysql_real_escape_string($this->getId_Pengguna()) . "','" 
                . mysql_real_escape_string($this->getId_Barang()) . "')";
        if (mysql_query($query)) {
            return "success";
        } else {
            return "error, " . mysql_error();
        }
    }
}